clearvars -except Globaloption option

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% This code reads in the VAR dynamics and produce the Campbell-Shiller decomposition in the paper
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Load data

loaddata_4CIjoint_annual;
ttime = [startdate:enddate];

if exist('option', 'var') == 0
    option.robust = 1;
end

if option.robust == 1
    output_rp = 0.03;
elseif option.robust == 2
    output_rp = 0.02;
end

%% Estimation
run ../../tools/cs_estimation.m

%% steady-state upper bound calculation
upper = exp(pxbar) * (mean(taxrevgdp - spendgdp));

gdpreturn = output_rp + y0nom_1 + yspr0 - pi0;

if option.robust==1
    save MAT/UKpostpara.mat k0x k1x s upper pdX pxbar gdpreturn
elseif option.robust==2
    save MAT/UKpostpara_20.mat k0x k1x s upper pdX pxbar gdpreturn gdebt
end

%% Bootstrap
run ../../tools/BS_compute.m
    
    
% save workspace
if option.robust == 1
    save MAT/benchmark_UK_30.mat startdatenum enddatenum s std_coeff gdebt upper k0x k1x pdT pdG taxrevgdp spendgdp pxbar
end





